﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditCustomer.aspx.cs" Inherits="Skyworth.CRM.Web.BasicData.EditCustomer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>销售管理平台 | 客户维护</title>
    <link href="../themes/<%= Request.Cookies["dwz_theme"]!=null? Request.Cookies["dwz_theme"].Value:"default" %>/style.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/core.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/pages.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/wbox.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/jTab.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/Messagebox.css" rel="stylesheet" type="text/css" />   
     
    <script src="../javascripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../javascripts/MessageBox.js" type="text/javascript"></script>
    <script src="../javascripts/dwz.core.js" type="text/javascript"></script>
    <%--<script src="../javascripts/jquery.tablesorter.min.js" type="text/javascript"></script>--%>
    <script src="../javascripts/dwz.pagination.js" type="text/javascript"></script>
    <script src="../javascripts/wbox.js" type="text/javascript"></script>
    <script src="../javascripts/json2.js" type="text/javascript"></script>
    <script src="../javascripts/jTab.js" type="text/javascript"></script>  
    <script src="../javascripts/jquery.autocomplete.js" type="text/javascript"></script>
    <style type="text/css">  
        .red
        {
            color: Red;
            font-weight: bold;
        }       
        table
        {
            border-collapse: collapse;
            border-spacing: 0;
            table-layout: fixed;
            /*border: solid 1px #e7e7e7;*/
        }
        table tr td
        {
            /*border-bottom: solid 1px #e7e7e7;)*/
            padding: 0px 3px;
            /*background-color: #EFEFEF;*/
        }
        td label
        {
            padding: 2px 2px;
        }
        td.left
        {
            /*border-right: solid 1px #e7e7e7;*/
            width: 60px;
        }
        /*td.right
        {
            background: #FFF;
        }*/
        td.right, td.readOnly
        {
            padding: 5px 3px;
        }
        .content
        {
            overflow: auto;           
            border: solid 1px #CCC;
            line-height: 21px;
            background: #FFF;
            padding: 2px;
        }       
        select
        {
        	width:135px;
        	height:22px;
        }        
    </style>  
    <script type="text/javascript">
        $(document).ready(function () {
            jTab.createjTab("jTabH", 'position:"horizontal"');
            $("#txtEmployee").autocomplete("../Service/EmployeeHandler.ashx", {
                minChars: 1, autoFill: false, scroll: false, mustMatch: true, selectFirst: true,
                formatItem: function (result, i, max) {
                    var item = "<span>" + result[1] + "(" + result[2] + ")</span>"
                    return item;
                },
                //extraParams: { CustId: 0 },
                formatResult: function (row) { return row[1]; }
            });
            $("#txtEmployee").result(function (event, data, formatted) {
                if (data && data.length > 0) {
                    $("#hidEmpId").val(data[0]);
                }
            });
            // 选择业务员弹出框
            //addWindow = $("#btnLookEmployee").wBox({ title: "查找员工信息", requestType: "iframe", target: "../Orders/SelectCust.aspx", iframeWH: { width: 420, height: 350} });

            $("#btnSave").click(function () {
                //debugger;
                var strCustCode = $("#txtCustCode").val();
                var strCustName = $("#txtCustName").val();
                var strCustLevel = $("#ddlstCustLevel").val();
                var strEmployee = $("#hidEmpId").val();
                var strQuHao = $("#txtQuHao").val();
                var strDianhua = $("#txtDianhua").val();
                var strShouji = $("#txtShouji").val();
                var strDescription = $("#txtDescription").val();
                var strCustId = $("#hidCustId").val();
                // 客户品牌
                var strCustBrand = $("#txtCustBrand").val();
                // 目标市场
                var strCustMarket = $("#txtCustMarket").val();
                // 主要经营产品
                var strProducts = $("#txtProducts").val();
                // 销售渠道
                var strChannels = $("#txtChannels").val();
                // 客户网站
                var strWebAddress = $("#txtWebAddress").val();
                if (strCustCode.length <= 0) {
                    alert("对不起,客户编号不能为空!");
                    $("#txtCustCode").focus();
                    return false;
                }
                if (strCustName.length <= 0) {
                    alert("对不起,客户名称不能为空!");
                    $("#txtCustName").focus();
                    return false;
                }
                // 获取联系人列表
                var contactList = "";
                $("#tbContact > tbody > tr").each(function () {
                    $(this).find('td').each(function () {
                        if ($(this).text() != "删除") {
                            contactList += $(this).text() + ",";
                        }
                    });
                    if (contactList.length > 0) {
                        contactList = contactList.substr(0, contactList.length - 1);
                    }
                    contactList += ";";
                });
                if (contactList.length > 0) {
                    contactList = contactList.substr(0, contactList.length - 1);
                }
                // 获取收货地址列表
                var addressList = "";
                $("#tbAddress > tbody > tr").each(function () {
                    $(this).find('td').each(function () {
                        if ($(this).text() != "删除") {
                            addressList += $(this).text() + ",";
                        }
                    });
                    if (addressList.length > 0) {
                        addressList = addressList.substr(0, addressList.length - 1);
                    }
                    addressList += ";";
                });
                if (addressList.length > 0) {
                    addressList = addressList.substr(0, addressList.length - 1);
                }
                var data = {
                    CustIdParas: strCustId,
                    CustParas: strCustCode + "," + strCustName + "," + strCustLevel + "," + strEmployee + "," + strQuHao + "," + strDianhua
                    + "," + strShouji + "," + strDescription + "," + strCustBrand + "," + strCustMarket + "," + strProducts + "," + strChannels
                    + "," + strWebAddress,
                    ContactParas: contactList,
                    AddressParas: addressList
                };
                $.post("../Service/CustHandler.ashx", data, function (result) {
                    if (result == "1") {
                        var url = "BasicData/Customer.aspx";
                        var pageTitle = "客户查询";
                        alert("恭喜您,保存数据成功!");
                        parent.navTab.openTab("dlg_page18", url, { title: pageTitle, isIframe: true });
                    }
                    else if (result == "2") {
                        alert("对不起,些客户编号己存在,请重新输入!");
                    }
                    else {
                        alert("对不起,程序错误,请联系系统管理员!");
                    }
                });
            })
        })
        //var row_count = 0;
        //var row_number = 0;
        function contactAddNew() {
            var strContactor = $("#txtContactor").val();
            if (strContactor.length > 0) {
                var strEmail = $("#txtEmail").val();
                var strTel = $("#txtTel").val();
                var strMobile = $("#txtMobile").val();
                var strIsDefault = $("#chkIsDefault").attr("checked");
                var strAddress = $("#txtAddress").val();
                var strHobby = $("#txtHobby").val();
                var strRemark = $("#txtRemark").val();
                var temp = false;
                $("#tbContact tr td:first-child").each(function () {
                    if ($(this).text() == strContactor) {
                        temp = true;
                        alert("对不起,此联系人己存在!");
                        return;
                    }
                })
                if (temp == false) {
                    $("#tbContact").append("<tr><td>" + strContactor + "</td><td>" + strEmail + "</td><td>" + strTel + "</td><td>" + strMobile
                 + "</td><td>" + strIsDefault + "</td><td>" + strAddress + "</td><td>" + strHobby + "</td><td>" + strRemark
                 + "</td><td><a href='javascript:void(0)' onclick='remove(this)'>删除</a></td></tr>");
                    //row_count++;
                }
            }
            else {
                alert("对不起,联系人不能为空!");
                return;
            }
        }
        function remove(node) {
            var curNode = node.parentNode.parentNode;
            $(curNode).remove();
        }
        function addressAddNew() {
            var strConsignee = $("#txtConsignee").val();
			var strLocation= $("#txtLocation").val();			
			if (strConsignee.length <= 0) {			
                alert("对不起,收货人不能为空!");
                return;
            }
			if(strLocation.length<=0){
			   alert("对不起,收货地址不能为空!");
               return false;
			}            
			var strPhone = $("#txtPhone").val();
			var strMob = $("#txtMob").val();
			var strCode = $("#txtCode").val();
			var temp = false;
			$("#tbAddress tr td:first-child").each(function () {
				if ($(this).text() == strConsignee) {
					temp = true;
					alert("对不起,此收货人己存在!");
					return;
				}
			})
			if (strCode.length > 0 && strCode.match(/\D/) != null) {
				alert("对不起,邮编只能为数字类型!");
				return;
			}
			if (temp == false) {
				$("#tbAddress").append("<tr><td>" + strConsignee + "</td><td>" + strPhone + "</td><td>" + strMob + "</td><td>" + strCode
			 + "</td><td>" + strLocation + "</td><td><a href='javascript:void(0)' onclick='remove(this)'>删除</a></td></tr>");
				//row_number++;
			}
            
           
        }
        // 弹出框
        function OpenEmployeeForm() {
            var url = "SelectEmployees.aspx";
            var model = "height=380,width=700,toolbar=no,menubar=no,scrollbars=yes,top=" + (screen.height - 380) / 2 + ",left=" + (screen.width - 700) / 2;
            //alert(url);
            window.open(url, "选择员工", model);
        }
    </script> 
</head>
<body>
    <div>
        <form id="form1" runat="server">
            <div class="panelContent">                         
                <div class="panelBar" style="width: 100%;">
                            <ul class="toolBar">
                                <li class="">
                                <%--<asp:LinkButton ID="btnAdd" CommandArgument="2" runat="server" CssClass="add"><span>保存</span> </asp:LinkButton>--%>
                                <a id="btnSave" class="add"><span>保存</span></a>
                                </li>                                
                            </ul>
                </div>         
            </div>
            <div class="pageFormContent" style="left:0px;height:160px;">
                <div class="content">
                <table cellpadding="0" cellspacing="0" border="0" width="98%" class="layout" id="layout1">
                    <tr>
                        <td class="left"><label>客户编码</label></td>
                        <td class="right">
                        <asp:TextBox ID="txtCustCode" CssClass="required textInput" runat="server" MaxLength="100" title="请输入客户编码!">
                        </asp:TextBox><input type="hidden" runat="server" id="hidCustId" value="0"/></td>
                        <td class="left"><label>客户名称</label></td>
                        <td class="right"><asp:TextBox ID="txtCustName" CssClass="required textInput" runat="server" MaxLength="200" title="请输入客户名称!"></asp:TextBox></td>
                        <td class="left"><label>客户级别</label></td>
                        <td class="right">
                            <asp:DropDownList ID="ddlstCustLevel" runat="server">
                                <asp:ListItem Value="0">请选择</asp:ListItem>
                                <asp:ListItem Value="1">A</asp:ListItem>
                                <asp:ListItem Value="2">B</asp:ListItem>
                                <asp:ListItem Value="3">C</asp:ListItem>
                                <asp:ListItem Value="4">D</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td class="left"><label>业 务 员</label></td>
                        <td class="right">
                            <asp:TextBox ID="txtEmployee" CssClass="txt" runat="server" Style="float: left; width: 130px" MaxLength="100"></asp:TextBox>
                            <a href ="javascript:OpenEmployeeForm()" class="btnLook" id="btnLookEmployee">查找</a>
                            <input type="hidden" style="display: none;" id="hidEmpId" value="0" runat="server" />
                        </td>
                    </tr>
                    <tr>                        
                        <td class="left"><label>区   号</label></td>
                        <td class="right"><asp:TextBox ID="txtQuHao" class="textInput" runat="server" MaxLength="50" title="请输入区号!"></asp:TextBox></td>
                        <td class="left"><label>电   话</label></td>
                        <td class="right"><asp:TextBox ID="txtDianhua" class="textInput" runat="server" MaxLength="50" title="请输入电话!"></asp:TextBox></td>
                        <td class="left"><label>手   机</label></td>
                        <td class="right"><asp:TextBox ID="txtShouji" class="textInput" runat="server" MaxLength="200" title="请输入手机!"></asp:TextBox></td>
                        <td class="left"><label>客户网站</label></td>
                        <td class="right"><asp:TextBox ID="txtWebAddress" Style="float: left; width: 130px" class="textInput" runat="server" MaxLength="100" title="请输入客户网站!"></asp:TextBox></td>
                    </tr>
                    <tr>                        
                        <td class="left">客户品牌</td>
                        <td class="right">
                        <asp:TextBox ID="txtCustBrand" CssClass="textInput" runat="server" 
                                MaxLength="100" title="请输入客户品牌!">
                        </asp:TextBox></td>
                        <td class="left">目标市场</td>
                        <td class="right"><asp:TextBox ID="txtCustMarket" CssClass="textInput" 
                                runat="server" MaxLength="200" title="请输入目标市场!"></asp:TextBox></td>
                        <td class="left">销售渠道</td>
                        <td class="right" colspan="3">
                            <asp:TextBox ID="txtChannels" class="textInput" runat="server" 
                                MaxLength="200" title="请输入销售渠道!" Width="390px"></asp:TextBox></td>
                    </tr>
                    <tr>                        
                        <td class="left">主要经营产品</td>
                        <td class="right" colspan="7">
                            <asp:TextBox ID="txtProducts" Width="912px" class="textInput" 
                                runat="server" MaxLength="500" title="请输入主要经营产品!"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>                        
                        <td><label>详细地址</label></td>
                        <td class="right" colspan="7">
                            <asp:TextBox ID="txtDescription" Width="912px" class="textInput" runat="server" 
                                MaxLength="200" title="请输入详细地址!"></asp:TextBox>
                        </td>
                    </tr>                    
                </table>	
             </div>
		</div>
        <div id="jTabH">
                    <span id="span1" class="jTab_hide">联系人</span>
                    <div id="div2" class="jTab_hide pageFormContent" style="height:100%">
                        <table cellpadding="0" cellspacing="0" border="0" width="930px">
                            <tr>
                                <td class="left"><label>联系人：</label></td>
                                <td class="right">
                                    <asp:TextBox ID="txtContactor" CssClass="required textInput" runat="server" MaxLength="100" title="请输入联系人!"></asp:TextBox>
                                </td>
                                <td class="left"><label>E-Mail：</label></td>
                                <td class="right"><asp:TextBox ID="txtEmail" CssClass="textInput" runat="server" MaxLength="100" title="请输入E-Mail!"></asp:TextBox></td>
                                <td class="left">电    话：</td>
                                <td class="right"><asp:TextBox ID="txtTel" CssClass="textInput" runat="server" MaxLength="50" title="请输入电话!"></asp:TextBox></td>
                                <td class="left">手    机：</td>
                                <td class="right"><asp:TextBox ID="txtMobile" CssClass="textInput" runat="server" MaxLength="50" title="请输入手机!"></asp:TextBox></td>
                            </tr>
                            <tr>
                            <td class="left"><label>地址：</label></td>
                                <td class="right" colspan="3"><asp:TextBox ID="txtAddress" Width="360px" CssClass="textInput" runat="server" MaxLength="150" title="请输入地址!"></asp:TextBox></td>                                
                                <td class="left"><label>爱   好：</label></td>
                                <td class="right" colspan="3">
                                    <asp:TextBox ID="txtHobby" Width="360px" CssClass="textInput" runat="server" MaxLength="150" title="请输入爱好!"></asp:TextBox>
                                </td>                            
                            </tr>
                            <tr>
                                <td class="left"><label>备   注：</label></td>
                                <td class="right" colspan="3">
                                    <asp:TextBox ID="txtRemark" Width="280px" CssClass="textInput" runat="server" MaxLength="250" title="请输入备注!"></asp:TextBox>
                                </td>         
                                <td class="left"><label>是否默认：</label></td>
                                <td class="right"><input id="chkIsDefault" type="checkbox" /></td>
                                <td colspan="2"><input type="button" class="okBut" value="新增" onclick="contactAddNew();" /></td> 
                            </tr>
                        </table>
                        <div class="pageContent">
                        <div class="tableList">
                            <table id="tbContact" class="list" width="100%">
                                <thead>
                                    <tr>                              
                                        <th width="70" style="cursor: pointer;" class="headerSortUp">
                                            <span style="float:left">联系人</span>
                                           <span style="float:right;" class="sortIcon"></span>                                
                                        </th>                         
                                        <th width="90" style="cursor: pointer;">
                                           <span style="float:left">E-Mail</span>
                                           <span style="float:right;" class="sortIcon"></span>
                                        </th>     
                                        <th width="90" style="cursor: pointer;">
                                           <span style="float:left">电话</span>
                                           <span style="float:right;" class="sortIcon"></span>
                                        </th>                             
                                        <th width="90" style="cursor: pointer;">
                                           <span style="float:left">手机</span>
                                        </th>     
                                        <th width="50" style="cursor: pointer;">
                                           <span style="float:left">是否默认</span>
                                        </th>     
                                         <th width="120" style="cursor: pointer;">
                                           <span style="float:left">地址</span>
                                        </th>
                                        <th width="120" style="cursor: pointer;">
                                           <span style="float:left">爱好</span>
                                        </th>     
                                        <th width="150" style="cursor: pointer;">
                                           <span style="float:left">备注</span>
                                        </th>
                                        <th width="30" style="cursor: pointer;">
                                           <span style="float:left">操作</span>
                                        </th>    
                                    </tr>
                                </thead>
                                <tbody>
                                    <asp:Literal ID="litContactList" runat="server"></asp:Literal>                              
                                </tbody>                    
                            </table>
                            </div>
                        </div>
                    </div>
                    <span id="span2" class="jTab_hide">收货地址</span>
                    <div id="div3" class="jTab_hide pageFormContent" style="height:100%">
                        <table cellpadding="0" cellspacing="0" border="0" width="930px">
                            <tr>
                                <td class="left"><label>收 货 人：</label></td>
                                <td class="right">
                                    <asp:TextBox ID="txtConsignee" CssClass="required textInput" runat="server" MaxLength="150" title="请输入收货人!"></asp:TextBox>
                                </td>
                                <td class="left">
                                    <label class="left">电   话：</label>
                                </td>
                                <td class="right">
                                    <asp:TextBox ID="txtPhone" CssClass="textInput" runat="server" MaxLength="50" title="请输入电话!"></asp:TextBox>
                                </td>  
                                <td class="left"><label class="left">手   机：</label></td>
                                <td class="right">
                                    <asp:TextBox ID="txtMob" CssClass="textInput" runat="server" MaxLength="50" title="请输入手机!"></asp:TextBox>
                                </td>
                                <td class="left"><label>邮   编：</label></td>
                                <td class="right">
                                    <asp:TextBox ID="txtCode" CssClass="textInput digits" runat="server" MaxLength="10" title="请输入数字!"></asp:TextBox>
                                </td>                                                           
                            </tr>
                            <tr>
                                <td class="left">
                                    <label>收货地址：</label>
                                </td>
                                <td class="right" colspan="3">
                                    <asp:TextBox ID="txtLocation" Width="360px" CssClass="required textInput" runat="server" MaxLength="150" title="请输入收货地址!"></asp:TextBox>
                                </td> 
                                <td colspan="4"><input type="button" class="okBut" value="新增" onclick="addressAddNew();" /></td>
                            </tr>
                       </table>
                        <div class="pageContent">
                            <div class="tableList">
                            <table id="tbAddress" class="list" width="100%">
                                <thead>
                                    <tr>   
                                        <th width="70" style="cursor: pointer;" class="headerSortUp">
                                           <span style="float:left">收货人</span>
                                           <span style="float:right;" class="sortIcon"></span>                                
                                        </th>
                                        <th width="90" style="cursor: pointer;">
                                           <span style="float:left">电话</span>
                                           <span style="float:right;" class="sortIcon"></span>
                                        </th>                             
                                        <th width="90" style="cursor: pointer;">
                                           <span style="float:left">手机</span>
                                        </th>     
                                        <th width="80" style="cursor: pointer;">
                                           <span style="float:left">邮编</span>
                                        </th>
                                        <th width="120" style="cursor: pointer;">
                                           <span style="float:left">收货地址</span>
                                           <span style="float:right;" class="sortIcon"></span>
                                        </th>
                                         <th width="30" style="cursor: pointer;">
                                           <span style="float:left">操作</span>
                                        </th>    
                                    </tr>
                                </thead>                                
                                <tbody>
                                    <asp:Literal ID="litAddressList" runat="server"></asp:Literal>                              
                                </tbody>                    
                            </table>
                            </div>
                        </div>
                    </div>
        </div>		
        </form>
    </div>
</body>
</html>